package cn.szq.springframework.context.support;

import cn.szq.springframework.beans.BeansException;
import cn.szq.springframework.beans.factory.ConfigurableListableBeanFactory;
import cn.szq.springframework.beans.factory.support.DefaultListableBeanFactory;

/***
 * All rights Reserved, Designed By www.jx-lab.com
 * @Title: AbstractRefreshableApplicationContext
 * @Description:
 * @author lixy
 * @date 2021/8/16 11:57
 * @version V1.0
 * @Copyright: www.jx-lab.com Inc. All rights reserved.
 * 注意：本内容仅限于众合景轩信息技术有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeansException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
